package com.nuoniu.sibanyun.mapper.crm;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.entity.crm.CrmActivity;
import com.nuoniu.sibanyun.entity.dto.CrmActivitySearchDto;
import com.nuoniu.sibanyun.entity.vo.CrmActivityVo;
import com.nuoniu.sibanyun.entity.vo.SelectVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author baiqiang
 * @since 2020-08-15
 */
public interface CrmActivityMapper extends BaseMapper<CrmActivity> {


    Page<CrmActivity> pageCrmActivity(Page page, @Param("dto") CrmActivitySearchDto crmActivitySearchDto,@Param("companyId")Integer companyId);

    @Select("SELECT * FROM crm_activity WHERE id = #{id}")
    CrmActivityVo getOne(Integer id);

    @Select("SELECT id AS `key`,activity_title AS title FROM crm_activity WHERE company_id = #{companyId} AND status = 0")
    List<SelectVo> listCompanyActivities(Integer companyId);

    @Select("SELECT COUNT(1) FROM  crm_activity WHERE id = #{id} AND ( activity_owner_id = #{userId} OR create_user_id = #{userId})")
    boolean isOwerOrCreater(Integer userId,Long id);
}
